//
//  CScenesManager.m
//  ibasketball2D
//
//  Created by imac on 11-5-25.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "CScenesManager.h"


@implementation CScenesManager

//静态场景管理实例
static CScenesManager* _sharedManager = nil;

//共享场景实例
+(id) SharedManager
{
	if (!_sharedManager) {
		_sharedManager = [[self alloc] init];
	}
	return _sharedManager;
}

//场景管理器初始化
-(id)init
{
	if( (self=[super init]) ) 
	{
		m_sceneTag = SceneTag_MainMenu;
		m_pScenes = [[NSMutableDictionary alloc] init];
		[self RemoveAllScene];
	}
	
	return self;
}

//释放内存
-(void)dealloc
{
	_sharedManager = nil;
	[m_pScenes release];
	[super dealloc];
}

//设置当前场景标识
//SceneTag: 传入场景标识
-(void)SetSceneTag:(SceneTag)scenetag
{
	m_sceneTag = scenetag;
}

//获取当前场景
-(SceneTag)getSceneTag
{
	return m_sceneTag;
}

//添加游戏场景
//id: 传入场景实例
//SceneTag: 传入场景标识
-(void)AddGameScene:(id)gamescene withTag:(SceneTag)tag
{
	if (m_pScenes) {
		if (([self GetSceneByTag:tag]) == nil) {
			[m_pScenes setObject:gamescene forKey:[NSString stringWithFormat:@"%d",tag]];
		}
	}
}

//获取游戏场景
//SceneTag: 传入场景标识
-(id)GetSceneByTag:(SceneTag)tag
{
	if (m_pScenes) {
		id temp = [m_pScenes objectForKey:[NSString stringWithFormat:@"%d",tag]];
		if (temp != nil) {
			return temp;
		}
	}
		return nil;
}

//移除游戏场景
//SceneTag: 传入需要移除的标识
-(void)RemoveSceneByTag:(SceneTag)tag
{
	if (m_pScenes) {
		[m_pScenes removeObjectForKey:[NSString stringWithFormat:@"%d",tag]];
	}
}

//移除所有场景
-(void)RemoveAllScene
{
	if (m_pScenes) {
		[m_pScenes removeAllObjects];
	}
}

@end
